define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'mall.order/index',
        add_url: 'mall.order/add',
        edit_url: 'mall.order/edit',
        delete_url: 'mall.order/delete',
        export_url: 'mall.order/export',
        modify_url: 'mall.order/modify',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
              //['refresh', 'add', 'delete', 'export']
                toolbar:['refresh', 'delete',  'export'],
                cols: [[
                    {type: 'checkbox'},                    {field: 'order_number', title: '订单号'},                    {field: 'uid', title: '用户信息',templet:function(d){
                    	return "<img style='max-width:25px;' src='"+d.user.avatar+"'></img>"+d.user.nickname;
                    }},                    {field: 'goods_info', title: '商品信息'},                    {field: 'price', title: '价格'},                    {field: 'real_payment', title: '实付款'},                    {field: 'discount', title: '优惠卷金额'},                    {field: 'status', title: '订单状态',search: false,templet:function(d){
                    	if(d.status == 1){
                    		return "待付款";
                    	}else if(d.status == 2){
                    		return "待发货";
                    	}else if(d.status == 3){
                    		return "待收货";
                    	}else if(d.status == 4){
                    		return "已完成";
                    	}
                    }},                    //{field: 'address', title: '详细地址'},                                        {field: 'pay_type', title: '支付方式',search: 'select', selectList: {"1":"微信","2":"余额","3":"套卡"},templet:function(d){
                    	if(d.pay_type == 1){
                    		return "微信";
                    	}else if(d.pay_type == 2){
                    		return "余额";
                    	}else if(d.pay_type == 3){
                    		return "套卡";
                    	}
                    }},                 /*   {field: 'type', title: '订单类型',templet:function(d){
                    	if(d.type == 1){
                    		return "商城订单";
                    	}else if(d.type == 2){
                    		return "兑换专区订单";
                    	}else if(d.type == 3){
                    		return "套卡";
                    	}else if(d.type == 4){
                    		return "充值";
                    	}
                    }},*/                    {field: 'store.title', title: '门店'},                    /*{field: 'receipt_type', title: '收货方式 ',templet:function(d){
                    	if(d.receipt_type == 1){
                    		return "到店自提<br>取货码:"+d.pickup_code;
                    	}else if(d.receipt_type == 2){
                    		return "邮寄";
                    	}
                    }},*/                    {field: 'remark', title: '备注', templet: ea.table.text},                  /*  {field: 'meal_id', title: '套餐id'},                    {field: 'refund_time', title: 'refund_time'},                    {field: 'pay_merchant', title: '1 微信商户 2 .宝付'},                    {field: 'ref_status', title: '退款状态 1 退款中 2 退款成功'},*/                    {field: 'goods_type', title: '订单类型',search: 'select', selectList: {"1":"商城订单","2":"服务预约"},templet:function(d){
                    	if(d.goods_type == 1){
                    		return "商城订单";
                    	}else if(d.goods_type == 2){
                    		return "服务预约";
                    	}else if(d.goods_type == 3){
                    		return "充值";
                    	}else if(d.goods_type == 4){
                    		return "套卡";
                    	}
                    }},
                    {field: 'createtime', title: '创建日期',search: 'range'},                    {width: 250, title: '操作', templet: "#test-table-operate-barDemo"},
                ]],
            });

            ea.listen();
        },
        platform_index: function () {
            ea.table.render({
                init: {
                    table_elem: '#currentTable',
                    table_render_id: 'currentTableRenderId',
                    index_url: 'mall.order/platform_index',
                    add_url: 'mall.order/add',
                    edit_url: 'mall.order/edit',
                    delete_url: 'mall.order/delete',
                    export_url: 'mall.order/export',
                    modify_url: 'mall.order/modify',
                },
              //['refresh', 'add', 'delete', 'export']
                toolbar:['refresh', 'delete',  'export'],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'order_number', title: '订单号'},
                    {field: 'uid', title: '用户信息',templet:function(d){
                    	return "<img style='max-width:25px;' src='"+d.user.avatar+"'></img>"+d.user.nickname;
                    }},
                    {field: 'goods_type', title: '订单类型',search: 'select', selectList: {"1":"商城订单","3":"充值","4":"套卡"},templet:function(d){
                    	if(d.goods_type == 1){
                    		return "商城订单";
                    	}else if(d.goods_type == 3){
                    		return "充值";
                    	}else if(d.goods_type == 4){
                    		return "套卡";
                    	}
                    }},
                    {field: 'goods_info', title: '商品信息'},
                    {field: 'price', title: '价格'},
                    {field: 'real_payment', title: '实付款'},
                    {field: 'discount', title: '优惠卷金额'},
                    {field: 'status', title: '订单状态',search: false,templet:function(d){
                    	if(d.status == 1){
                    		return "待付款";
                    	}else if(d.status == 2){
                    		return "待发货";
                    	}else if(d.status == 3){
                    		return "待收货";
                    	}else if(d.status == 4){
                    		return "已完成";
                    	}
                    }},
                    //{field: 'address', title: '详细地址'},
                    
                    {field: 'pay_type', title: '支付方式',search: 'select', selectList: {"1":"微信","2":"余额","3":"套卡"},templet:function(d){
                    	if(d.pay_type == 1){
                    		return "微信";
                    	}else if(d.pay_type == 2){
                    		return "余额";
                    	}else if(d.pay_type == 3){
                    		return "套卡";
                    	}
                    }},
                 /*   {field: 'type', title: '订单类型',templet:function(d){
                    	if(d.type == 1){
                    		return "商城订单";
                    	}else if(d.type == 2){
                    		return "兑换专区订单";
                    	}else if(d.type == 3){
                    		return "套卡";
                    	}else if(d.type == 4){
                    		return "充值";
                    	}
                    }},*/
                   // {field: 'store.title', title: '门店'},
                    /*{field: 'receipt_type', title: '收货方式 ',templet:function(d){
                    	if(d.receipt_type == 1){
                    		return "到店自提<br>取货码:"+d.pickup_code;
                    	}else if(d.receipt_type == 2){
                    		return "邮寄";
                    	}
                    }},*/
                    {field: 'remark', title: '备注', templet: ea.table.text},
                  /*  {field: 'meal_id', title: '套餐id'},
                    {field: 'refund_time', title: 'refund_time'},
                    {field: 'pay_merchant', title: '1 微信商户 2 .宝付'},
                    {field: 'ref_status', title: '退款状态 1 退款中 2 退款成功'},*/
                   
                    {field: 'createtime', title: '创建日期',search: 'range'},
                    {width: 250, title: '操作', templet: "#test-table-operate-barDemo"},
                ]],
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
        	
        	 var id = $('#order_id').val();
        	 layui.table.render({
                 elem: '#currentTable'
                 ,url:"orderGoods?id="+id
                 ,cellMinWidth: 80
                 ,cols: [[
                     {field:'title', width:'25%', title: '商品名称',templet:function(d){
					    return d.title;
					}}
					,{field:'logo', width:'25%', title: '商品图片',templet:function(d){
					    return "<img style='max-width:25px;' src='"+d.logo+"'></img>";
					}}
					,{field:'unit_price', width:'25%', title: '单价', sort: true}
					,{field:'num',width:'25%', title: '数量', sort: true}
                 ]]
                 ,page: false
             });
        	 
        	 layui.table.render({
                 elem: '#currentTableService'
                 ,url:"orderGoods?id="+id
                 ,cellMinWidth: 80
                 ,cols: [[
                     {field:'title', width:'25%', title: '商品名称',templet:function(d){
					    return d.title;
					}}
					,{field:'logo', width:'25%', title: '商品图片',templet:function(d){
					    return "<img style='max-width:25px;' src='"+d.logo+"'></img>";
					}}
					,{field:'unit_price', width:'25%', title: '单价', sort: true}
					,{field:'num',width:'25%', title: '数量', sort: true}
                 ]]
                 ,page: false
             });
        	 
        	/* layui.table.render({
                 elem: '#currentTable'
                 ,url:"orderGoods?id="+id
                 ,cellMinWidth: 80
                 ,cols: [[
                     {field:'title', width:'25%', title: '商品名称',templet:function(d){
					    return d.title;
					}}
					,{field:'logo', width:'25%', title: '商品图片',templet:function(d){
					    return "<img style='max-width:25px;' src='"+d.logo+"'></img>";
					}}
					,{field:'unit_price', width:'25%', title: '单价', sort: true}
					,{field:'num',width:'25%', title: '数量', sort: true}
                 ]]
                 ,page: false
             });*/
        	 
    
            ea.listen();
        },
    };
    return Controller;
});